/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package cn.edu.zjut.baoge.lang;

import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 张坤
 * @DateTime: 2022/2/15 17:44
 * @Description: 该类用于 返回值格式规范
 */
public class ResultBean extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;

	public ResultBean() {
		put("code", 0);
		put("msg", "success");
	}

	public static ResultBean error() {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
	}

	public static ResultBean error(String msg) {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
	}

	public static ResultBean error(int code, String msg) {
		ResultBean resultBean = new ResultBean();
		resultBean.put("code", code);
		resultBean.put("msg", msg);
		return resultBean;
	}

	public static ResultBean ok(String msg) {
		ResultBean resultBean = new ResultBean();
		resultBean.put("msg", msg);
		return resultBean;
	}

	public static ResultBean ok(Map<String, Object> map) {
		ResultBean resultBean = new ResultBean();
		resultBean.putAll(map);
		return resultBean;
	}

	public static ResultBean ok() {
		return new ResultBean();
	}

	@Override
	public ResultBean put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
